package com.hspedu.com.jdbc;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * @author DL5O
 * @version 1.0
 */
public class TestJDBC {
    public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException {
        Properties properties = new Properties();
        properties.load(new FileReader("src\\jdbc.properties"));
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");
        String driver = properties.getProperty("driver");

        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);
        Statement statement = connection.createStatement();
        String insertSql = null;
        /*for (int i = 1; i <= 5; i++) {
            insertSql = "insert into news(id,content) values(+"+ i + ",'新闻 " + i + "')";
            statement.execute(insertSql);
        }*/

        String updateSql = "update news set content='敲代码真快乐哈哈哈' where id = 1";
        statement.execute(updateSql);

        String deleteSql = "delete from news where id = 3";
        statement.execute(deleteSql);
    }
}
